home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / CIncludes / NumberFormatting.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-12  |  4.5 KB  |  195 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        NumberFormatting.h
  3.  
  4.      Contains:    Utilites for formatting numbers
  5.  
  6.      Version:    Technology:    
  7.                  Release:    Universal Interfaces 3.0.1
  8.  
  9.      Copyright:    © 1996-1997 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. */
  18. #ifndef __NUMBERFORMATTING__
  19. #define __NUMBERFORMATTING__
  20.  
  21. #ifndef __CONDITIONALMACROS__
  22. #include <ConditionalMacros.h>
  23. #endif
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27. #ifndef __INTLRESOURCES__
  28. #include <IntlResources.h>
  29. #endif
  30.  
  31.  
  32.  
  33.  
  34. #if PRAGMA_ONCE
  35. #pragma once
  36. #endif
  37.  
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41.  
  42. #if PRAGMA_IMPORT
  43. #pragma import on
  44. #endif
  45.  
  46. #if PRAGMA_STRUCT_ALIGN
  47.     #pragma options align=mac68k
  48. #elif PRAGMA_STRUCT_PACKPUSH
  49.     #pragma pack(push, 2)
  50. #elif PRAGMA_STRUCT_PACK
  51.     #pragma pack(2)
  52. #endif
  53.  
  54. /*
  55.  
  56.     Here are the current System 7 routine names and the translations to the older forms.
  57.     Please use the newer forms in all new code and migrate the older names out of existing
  58.     code as maintainance permits.
  59.     
  60.     New Name                    Old Name(s)
  61.     
  62.     ExtendedToString            FormatX2Str
  63.     FormatRecToString            Format2Str
  64.     NumToString                
  65.     StringToExtended            FormatStr2X
  66.     StringToFormatRec            Str2Format
  67.     StringToNum                
  68.  
  69. */
  70. struct NumFormatString {
  71.     UInt8                             fLength;
  72.     UInt8                             fVersion;
  73.     char                             data[254];                    /* private data */
  74. };
  75. typedef struct NumFormatString NumFormatString;
  76.  
  77. typedef NumFormatString                 NumFormatStringRec;
  78. typedef short                             FormatStatus;
  79.  
  80. enum {
  81.     fVNumber                    = 0                                /* first version of NumFormatString */
  82. };
  83.  
  84. typedef SInt8                             FormatClass;
  85.  
  86. enum {
  87.     fPositive                    = 0,
  88.     fNegative                    = 1,
  89.     fZero                        = 2
  90. };
  91.  
  92. typedef SInt8                             FormatResultType;
  93.  
  94. enum {
  95.     fFormatOK                    = 0,
  96.     fBestGuess                    = 1,
  97.     fOutOfSynch                    = 2,
  98.     fSpuriousChars                = 3,
  99.     fMissingDelimiter            = 4,
  100.     fExtraDecimal                = 5,
  101.     fMissingLiteral                = 6,
  102.     fExtraExp                    = 7,
  103.     fFormatOverflow                = 8,
  104.     fFormStrIsNAN                = 9,
  105.     fBadPartsTable                = 10,
  106.     fExtraPercent                = 11,
  107.     fExtraSeparator                = 12,
  108.     fEmptyFormatString            = 13
  109. };
  110.  
  111. struct FVector {
  112.     short                             start;
  113.     short                             length;
  114. };
  115. typedef struct FVector FVector;
  116.  
  117. /* index by [fPositive..fZero] */
  118. typedef FVector                         TripleInt[3];
  119. #if CGLUESUPPORTED
  120. EXTERN_API_C( void )
  121. stringtonum                        (const char *            theString,
  122.                                  long *                    theNum);
  123.  
  124. EXTERN_API_C( void )
  125. numtostring                        (long                     theNum,
  126.                                  char *                    theString);
  127.  
  128. #endif  /* CGLUESUPPORTED */
  129.  
  130. EXTERN_API( void )
  131. StringToNum                        (ConstStr255Param         theString,
  132.                                  long *                    theNum);
  133.  
  134. EXTERN_API( void )
  135. NumToString                        (long                     theNum,
  136.                                  Str255                 theString);
  137.  
  138.  
  139. EXTERN_API( FormatStatus )
  140. ExtendedToString                (const extended80 *        x,
  141.                                  const NumFormatString * myCanonical,
  142.                                  const NumberParts *    partsTable,
  143.                                  Str255                 outString)                            FOURWORDINLINE(0x2F3C, 0x8210, 0xFFE8, 0xA8B5);
  144.  
  145. EXTERN_API( FormatStatus )
  146. StringToExtended                (ConstStr255Param         source,
  147.                                  const NumFormatString * myCanonical,
  148.                                  const NumberParts *    partsTable,
  149.                                  extended80 *            x)                                    FOURWORDINLINE(0x2F3C, 0x8210, 0xFFE6, 0xA8B5);
  150.  
  151. EXTERN_API( FormatStatus )
  152. StringToFormatRec                (ConstStr255Param         inString,
  153.                                  const NumberParts *    partsTable,
  154.                                  NumFormatString *        outString)                            FOURWORDINLINE(0x2F3C, 0x820C, 0xFFEC, 0xA8B5);
  155.  
  156. EXTERN_API( FormatStatus )
  157. FormatRecToString                (const NumFormatString * myCanonical,
  158.                                  const NumberParts *    partsTable,
  159.                                  Str255                 outString,
  160.                                  TripleInt                 positions)                            FOURWORDINLINE(0x2F3C, 0x8210, 0xFFEA, 0xA8B5);
  161.  
  162.  
  163. #if OLDROUTINENAMES
  164. #define FormatX2Str(x, myCanonical, partsTable, outString)  \
  165.          ExtendedToString( x, myCanonical, partsTable, outString)
  166. #define FormatStr2X(source, myCanonical, partsTable, x)  \
  167.          StringToExtended( source, myCanonical, partsTable, x)
  168. #define Str2Format(inString, partsTable, outString)  \
  169.          StringToFormatRec(inString, partsTable, outString)
  170. #define Format2Str(myCanonical, partsTable, outString, positions)  \
  171.          FormatRecToString(myCanonical, partsTable, outString, positions)
  172. #endif  /* OLDROUTINENAMES */
  173.  
  174.  
  175. #if PRAGMA_STRUCT_ALIGN
  176.     #pragma options align=reset
  177. #elif PRAGMA_STRUCT_PACKPUSH
  178.     #pragma pack(pop)
  179. #elif PRAGMA_STRUCT_PACK
  180.     #pragma pack()
  181. #endif
  182.  
  183. #ifdef PRAGMA_IMPORT_OFF
  184. #pragma import off
  185. #elif PRAGMA_IMPORT
  186. #pragma import reset
  187. #endif
  188.  
  189. #ifdef __cplusplus
  190. }
  191. #endif
  192.  
  193. #endif /* __NUMBERFORMATTING__ */
  194.  
  195.